﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Globalization;

namespace JoyeriaProject
{
    public partial class frmCustomerDetailGrid : Form
    {
        DatabaseManager DM;
        ModeloDatos MD;
        DataTable DT;

        int CUSTOMERID;

        public frmCustomerDetailGrid(int CustomerID)
        {
            InitializeComponent();

            this.CUSTOMERID = CustomerID;
            MD = new ModeloDatos(1);

            var tt = from n in MD.GetClients()
                     where n.CustomerID == CustomerID
                     select new { ID = n.CustomerID, NombreCompleto = n.Nombre + " " + n.Apellidos };

            lblID.Text = CustomerID.ToString();

            lblNombre.Text = tt.Min(n => n.NombreCompleto).ToString();
            
           
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void frmCustomerDetailGrid_Load(object sender, EventArgs e)
        {
              DM = new DatabaseManager();
            
              DT = DM.GridSourcer3("SELECT * FROM PAYMENTS WHERE CUSTOMERID = " + CUSTOMERID).Tables[0];
 
              dataGridComprasPagos.DataSource = DT;
              
              dataGridComprasPagos.Columns["FECHAS"].ReadOnly = true;

              dataGridComprasPagos.Columns["FECHA"].Visible = false;

              dataGridComprasPagos.Columns["CUSTOMERID"].Visible = false;

              dataGridComprasPagos.Columns["ID"].Visible = false;

              dataGridComprasPagos.Columns["STATUS"].Visible = false;

              dataGridComprasPagos.Columns["SALDO"].Visible = false;

              dataGridComprasPagos.Columns["ARTICULO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;  
              
              dataGridComprasPagos.Columns["ARTICULO"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
   
        }

        private void dataGridComprasPagos_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
           
            // DataRow tt = DM.dTable.Rows[e.RowIndex];
              
            // string hh =  tt.ItemArray[e.ColumnIndex].ToString();

            //// DT.AcceptChanges();

            // DM.Adapter.Update(DT);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DM.AddGridChanges();
        }

    }
}
